import scrapy


class RediseScSpider(scrapy.Spider):
    name = "redise_sc"

    async def start(self):
        yield scrapy.Request("https://quotes.toscrape.com")

    def parse(self, response):
        self.log(f"正在爬取{response.url}")
        items = response.xpath('//div[@class="quote"]')
        for item in items:

            data = {
                "author": item.xpath('.//small[@class="author"]/text()').get(),
                "text": item.xpath('./span[@class="text"]/text()').get(),
                "tags": item.xpath('.//a[@class="tag"]/text()').getall(),
            }
            yield data

        next_url = response.xpath('//li[@class="next"]/a/@href').get()
        if next_url:
            yield response.follow(next_url)
